package com.liuyucheng.generic.wildcard;

import java.util.ArrayList;

public class TestWildCardUpLimit {
    public static void main(String[] args) {
        ArrayList<Animal> animals = new ArrayList<>();
        ArrayList<Cat> cats = new ArrayList<>();
        ArrayList<MiniCat> miniCats = new ArrayList<>();

//        showAnimal(animals);
        showAnimal(cats);
        showAnimal(miniCats);
    }

    /**
     * 泛型上限通配符，传递的类型，只能是Cat或者它的子类
     * @param list 集合
     */
    public static void showAnimal(ArrayList<? extends Cat> list){
//        list.add(new MiniCat());
//        list.add(new Cat());
//        list.add(new Animal());
        for(Cat cat : list){
            System.out.println("cat = " + cat);
        }
    }
}
